import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTabWidget
from .product_manage import ProductManagementWidget
from .order_manage import OrderManagementWidget
from .dataAnalytics import AnalyticsWidget
from .llm_window import LLMWidget

class ShopManage(QWidget):
    def __init__(self, login_widget=None):
        super().__init__()
        self.login_widget = login_widget  # 存储登录窗口实例
        self.setWindowTitle("购物管理系统")
        self.setGeometry(100, 100, 1200, 900)
        self.setWindowIcon(QIcon('./images/购物.png'))
        self.create_main_content()

    def create_main_content(self):
        layout = QVBoxLayout()
        layout.setContentsMargins(10, 10, 10, 10)
        layout.setSpacing(10)

        self.tab_widget = QTabWidget()
        self.tab_widget.setStyleSheet("""
            QTabWidget::pane {
                border: 1px solid #ccc;
                background-color: #f8f8f8;
            }
            QTabBar::tab {
                background: #e0e0e0;
                border: 1px solid #ccc;
                padding: 8px 12px;
                border-top-left-radius: 4px;
                border-top-right-radius: 4px;
            }
            QTabBar::tab:selected {
                background: #ffffff;
                border-bottom-color: #ffffff;
            }
        """)

        # 传递 login_widget 给 ProductManagementWidget
        self.product_management = ProductManagementWidget(login_widget=self.login_widget, parent=self)
        self.tab_widget.addTab(self.product_management, "商品管理")

        # 添加订单管理标签页
        self.order_management = OrderManagementWidget()
        self.tab_widget.addTab(self.order_management, "订单管理")

        # 添加数据分析标签页
        self.data_Analytics = AnalyticsWidget()
        self.tab_widget.addTab(self.data_Analytics, "数据分析")

        # 添加AI客服标签页
        self.LLMWidget = LLMWidget()
        self.tab_widget.addTab(self.LLMWidget, "AI客服")

        layout.addWidget(self.tab_widget)
        self.setLayout(layout)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = ShopManage()
    window.show()
    sys.exit(app.exec_())